<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <!-- 查看本地图片 二进制方式 -->
    <input type="file" id="file" />
    <button id="show">显示本地图片</button>
    <br>
    <img src="" alt="" id="img" width="800" />
    <script>
        var show = document.querySelector('#show')
        show.addEventListener('click', function () {
            var files = document.querySelector('#file').files
            if (files.length <= 0) {
                return alert('请选择要上传的文件！')
            }
            console.log('本地图片地址：'+getFileURL(files[0]));
            document.querySelector('#img').src = getFileURL(files[0])
        })
        const getFileURL = file => {
            var getUrl = null;
            if (window.createObjectURL != undefined) { // basic
                getUrl = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                getUrl = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                getUrl = window.webkitURL.createObjectURL(file);
            }
            return getUrl;
        }
    </script>
</body>

</html>